package cn.com.b2office.exchange;

import java.io.Serializable;
import java.util.Collections;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;

import cn.com.b2office.domain.AccountActivity;
import cn.com.b2office.domain.Category;
import cn.com.b2office.domain.City;
import cn.com.b2office.domain.County;
import cn.com.b2office.domain.DeliveryMode;
import cn.com.b2office.domain.DeliveryTime;
import cn.com.b2office.domain.DictData;
import cn.com.b2office.domain.DictType;
import cn.com.b2office.domain.District;
import cn.com.b2office.domain.ExData;
import cn.com.b2office.domain.Item;
import cn.com.b2office.domain.ItemCollection;
import cn.com.b2office.domain.Member;
import cn.com.b2office.domain.MemberAddress;
import cn.com.b2office.domain.OOSReport;
import cn.com.b2office.domain.Order;
import cn.com.b2office.domain.OrderItem;
import cn.com.b2office.domain.PaymentMode;
import cn.com.b2office.domain.Province;
import cn.com.b2office.domain.SCAssociation;
import cn.com.b2office.domain.Shop;
import cn.com.b2office.domain.SpecialCategory;
import cn.com.b2office.domain.SpecialItem;

public class ClassMapping {

	public static final int INTEGER = 1;

	public static final int STRING = 0;

	private static Map<Integer, Class> mapping = new HashMap<Integer, Class>();

	private static Map<Class, Integer> class_mapping = new HashMap<Class, Integer>();

	private static Map<Integer, Integer> pk_type_map = new HashMap<Integer, Integer>();

	static {
		mapping = Collections.synchronizedMap(mapping);
		mapping.put(1, Item.class);
		mapping.put(2, Category.class);
		mapping.put(3, DictType.class);
		mapping.put(4, DictData.class);
		mapping.put(5, County.class);
		mapping.put(6, District.class);
		mapping.put(7, City.class);
		mapping.put(8, Province.class);
		// map.put(9, ServiceFrequency.class);
		// map.put(10, ServiceMode.class);
		// map.put(11, PublishedService.class);
		// map.put(12, PublishedServiceClass.class);
		mapping.put(13, PaymentMode.class);
		mapping.put(14, DeliveryTime.class);
		mapping.put(15, DeliveryMode.class);
		// map.put(16, FreshTopClass.class);
		// map.put(17, FreshSecondClass.class);
		// map.put(18, FreshThirdClass.class);
		// mapping.put(19, ClsRecmd.class);
		// map.put(20, GroupBuy.class);
		// map.put(21, Account.class);
		// mapping.put(22, Comment.class);
		// mapping.put(23, HotWords.class);
		mapping.put(24, Member.class);
		// mapping.put(27, LatestBuyItem.class);
		// mapping.put(28, MemberConcern.class);
		mapping.put(29, ItemCollection.class);
		// mapping.put(30, LargestAmountBuyItem.class);
		// map.put(31, GroupBuyApply.class);
		mapping.put(32, AccountActivity.class);
		mapping.put(33, OOSReport.class);
		mapping.put(34, MemberAddress.class);
		// mapping.put(35, MostFrequentBuyItem.class);
		mapping.put(36, Order.class);
		mapping.put(37, OrderItem.class);
		// mapping.put(38, PageBottom.class);
		mapping.put(39, SCAssociation.class);
		mapping.put(40, SpecialCategory.class);
		mapping.put(41, Shop.class);
		mapping.put(42, SpecialItem.class);
		mapping.put(43, ExData.class);

		Iterator<Integer> iterator = mapping.keySet().iterator();
		while (iterator.hasNext()) {
			Integer key = iterator.next();
			Class clasz = mapping.get(key);
			class_mapping.put(clasz, key);
		}

		pk_type_map.put(1, STRING);
		pk_type_map.put(2, STRING);

		pk_type_map.put(3, INTEGER);
		pk_type_map.put(4, INTEGER);
		pk_type_map.put(5, INTEGER);
		pk_type_map.put(6, INTEGER);
		pk_type_map.put(7, INTEGER);
		pk_type_map.put(8, INTEGER);
		pk_type_map.put(9, INTEGER);
		pk_type_map.put(10, INTEGER);
		pk_type_map.put(11, INTEGER);
		pk_type_map.put(12, STRING);
		pk_type_map.put(13, INTEGER);
		pk_type_map.put(14, INTEGER);
		pk_type_map.put(15, INTEGER);
		pk_type_map.put(16, INTEGER);
		pk_type_map.put(17, INTEGER);
		pk_type_map.put(18, INTEGER);
		pk_type_map.put(19, INTEGER);
		pk_type_map.put(20, INTEGER);
		pk_type_map.put(21, STRING);
		pk_type_map.put(22, INTEGER);
		pk_type_map.put(23, INTEGER);
		pk_type_map.put(24, STRING);
		pk_type_map.put(27, INTEGER);
		pk_type_map.put(28, INTEGER);
		pk_type_map.put(29, INTEGER);
		pk_type_map.put(30, INTEGER);
		pk_type_map.put(31, INTEGER);
		pk_type_map.put(32, STRING);
		pk_type_map.put(33, INTEGER);
		pk_type_map.put(34, STRING);
		pk_type_map.put(35, INTEGER);
		pk_type_map.put(36, STRING);
		pk_type_map.put(37, STRING);
		pk_type_map.put(38, INTEGER);
		pk_type_map.put(39, INTEGER);
		pk_type_map.put(40, INTEGER);
		pk_type_map.put(41, INTEGER);
		pk_type_map.put(42, STRING);
		pk_type_map.put(43, INTEGER);
	}

	public static Class getClass(int entity) {
		return mapping.get(entity);
	}

	public static Integer getClassCode(Class clasz) {
		return class_mapping.get(clasz);
	}

	public static Serializable getId(int entity, String entityId) {
		if (pk_type_map.get(entity) == STRING)
			return entityId;
		else
			return Integer.valueOf(entityId);
	}
}
